package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Attendance;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Mission;
import cn.wolfcode.crm.mapper.EmployeeMapper;
import cn.wolfcode.crm.mapper.MissionMapper;
import cn.wolfcode.crm.query.MissionQueryObject;
import cn.wolfcode.crm.service.IMissionService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class MissionServiceImpl implements IMissionService {


    @Autowired
    private MissionMapper missionMapper;

    @Autowired
    EmployeeMapper employeeMapper;

    public int deleteByPrimaryKey(Long id) {
        return missionMapper.deleteByPrimaryKey(id);
    }

    public int insert(Mission record) {
        return missionMapper.insert(record);
    }

    public Mission selectByPrimaryKey(Long id) {
        return missionMapper.selectByPrimaryKey(id);
    }

    public List<Mission> selectAll() {
        return missionMapper.selectAll();
    }

    public int updateByPrimaryKey(Mission record) {
        return missionMapper.updateByPrimaryKey(record);
    }

    public PageResult query(MissionQueryObject qo) {
        int count = missionMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.emptyList());
        }
        List<Attendance> attendances = missionMapper.queryList(qo);
        return new PageResult(count, attendances);
    }

    public void changeState(Boolean state, Long id) {
        missionMapper.changeState(state, id);
    }

    public Boolean validateName(String employeeuserame) {

        Employee employee = employeeMapper.selectByUsername(employeeuserame);
        System.out.println(employee);

        if (employee != null) {
            return true;
        } else {
            return false;
        }
    }



}
